'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');

var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _util = require('./util');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var MenuItemGroup = function (_React$Component) {
  (0, _inherits3['default'])(MenuItemGroup, _React$Component);

  function MenuItemGroup() {
    var _temp, _this, _ret;

    (0, _classCallCheck3['default'])(this, MenuItemGroup);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = (0, _possibleConstructorReturn3['default'])(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.renderInnerMenuItem = function (item) {
      var _this$props = _this.props,
          renderMenuItem = _this$props.renderMenuItem,
          index = _this$props.index;

      return renderMenuItem(item, index, _this.props.subMenuKey);
    }, _temp), (0, _possibleConstructorReturn3['default'])(_this, _ret);
  }

  MenuItemGroup.prototype.render = function render() {
    var props = (0, _objectWithoutProperties3['default'])(this.props, []);

    var _props$className = props.className,
        className = _props$className === undefined ? '' : _props$className,
        rootPrefixCls = props.rootPrefixCls;

    var titleClassName = rootPrefixCls + '-item-group-title';
    var listClassName = rootPrefixCls + '-item-group-list';
    var title = props.title,
        children = props.children;

    _util.menuAllProps.forEach(function (key) {
      return delete props[key];
    });

    // Set onClick to null, to ignore propagated onClick event
    delete props.onClick;

    return _react2['default'].createElement('li', (0, _extends3['default'])({}, props, { className: className + ' ' + rootPrefixCls + '-item-group' }), _react2['default'].createElement('div', {
      className: titleClassName,
      title: typeof title === 'string' ? title : undefined
    }, title), _react2['default'].createElement('ul', { className: listClassName }, _react2['default'].Children.map(children, this.renderInnerMenuItem)));
  };

  return MenuItemGroup;
}(_react2['default'].Component);

MenuItemGroup.propTypes = {
  renderMenuItem: _propTypes2['default'].func,
  index: _propTypes2['default'].number,
  className: _propTypes2['default'].string,
  subMenuKey: _propTypes2['default'].string,
  rootPrefixCls: _propTypes2['default'].string
};
MenuItemGroup.defaultProps = {
  disabled: true
};

MenuItemGroup.isMenuItemGroup = true;

exports['default'] = MenuItemGroup;
module.exports = exports['default'];